<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<script>
    //浏览器规定如果协议,域名，或者端口号任何一个不一样，就会产生跨域
    // http://localhost:3000
    // https://127.0.0.1:8080
    //查看用户
   /*  let xhr = new XMLHttpRequest();
    //是否在请求携带cookie
    xhr.withCredentials=true;
    xhr.open('GET','http://localhost:3000?id=1',true);
    xhr.onload = ()=>{
        console.log(xhr.responseText)
    }
    xhr.send(); */

   //添加用户
    let xhr = new XMLHttpRequest();
    //允许ajax请求时携带cookie
    xhr.withCredentials=true;
    xhr.open('POST','http://localhost:3000',true);
    xhr.setRequestHeader('Content-Type','application/json');
    xhr.onload = ()=>{
        console.log(xhr.responseText)
    }
    xhr.send(JSON.stringify({name:'zhufeng'}));
    /*
    //删除用户
    let xhr = new XMLHttpRequest();
    xhr.open('DELETE','http://localhost:3000?id=1',true);
    xhr.onload = ()=>{
        console.log(xhr.responseText)
    }
    xhr.send(); */
</script>
</body>
</html>